package gui.components.objectinfo;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import simulation.Config;

public class System_General {
	private JPanel top = new JPanel();
	
	public JPanel createPanelElements(){
		JPanel pnlMain = new JPanel(new GridLayout(1,1));

		top.setBorder(BorderFactory.createTitledBorder("CONNECTION"));
			JPanel pnlServer = new JPanel(new GridLayout(3,1));
				JLabel lblServerIP = new JLabel("Server IP");
			pnlServer.add(lblServerIP);
			pnlServer.add(new JLabel(Config.cajoHost));
				JLabel lblServerPort = new JLabel("Server port");
			pnlServer.add(lblServerPort);
			pnlServer.add(new JLabel("" + Config.cajoPort));
			JLabel lblClientIP = new JLabel("Client IP");
			pnlServer.add(lblClientIP);
			//Call the IP address function
			pnlServer.add(new JLabel(getLocalIPAddress()));
			
			pnlServer.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 80));
			pnlServer.setPreferredSize(new Dimension(250, 75));
		top.add(pnlServer);
		top.setPreferredSize(new Dimension(335, 120));		
		pnlMain.add(top);
		return pnlMain;
	}
	//function to get the local IP address
	private String getLocalIPAddress(){
		String ipAddress = "127.0.0.1";
		try{
			InetAddress addr = InetAddress.getLocalHost();
			ipAddress = addr.getHostAddress();
		} 
		catch (UnknownHostException e) {
			//IP Address cannot be resolved
		}
		//Return the IP address
		return ipAddress;
	}
}

